/*
    26. Write a program in C to count the number of punctuation characters exists in a string.
    Test Data :
    Input a string : The quick brown fox, jumps over the, lazy dog.

    Expected Output :

    The punctuation characters exists in the string is : 3 
*/

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX_LEN 1024
#define MAX_STR 256

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p++ = ch;
    }
    *p = '\0';
    return str;
}

int countpunchar(char *str)
{
    int cnt = 0;
    while(*str){
        if(ispunct(*str)){
            cnt++;
        }
        str++;
    }
    return cnt;
}

int main(void)
{
    char *str = malloc(MAX_LEN);
    printf("Input a string : ");
    getstr(str);
    printf("The punctuation characters exists in the string is : %d", countpunchar(str));

    return 0;
}